package com.aeks.show;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.aeks.DB.OperateDB;
import com.aeks.divide.FileDivide;

public class FinalShow {
	public static List<String> getArticle(String saveName, String fileName, String servletPath) {
		List<String> article = new ArrayList<String>();
		
		String path = servletPath + "tempFile";
		String articleFile = path + "\\" + saveName + fileName;
		System.out.println("articlefile:" + articleFile);
		File af = new File(articleFile);
		if(af.exists()) {
			FileReader fr;
			try {
				fr = new FileReader(af);
				BufferedReader br = new BufferedReader(fr);
				String s = br.readLine();
				while(s!= null) {
					article.add(s);
					s = br.readLine();
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				return null;
			} catch (IOException e) {
				e.printStackTrace();
				return null;
			}
		} else {
			return null;
		}
		return article;
	}
	
	public static List<String> getStop(String saveName, String servletPath) {
		List<String> stop = new ArrayList<String>();
		
		String path = servletPath + "tempFile";
		String stopFile = path + "\\" + saveName + "usedStop.txt";
		System.out.println("stopfile:" + stopFile);
		File sf = new File(stopFile);
		
		if(sf.exists()) {
			FileReader fr;
			try {
				fr = new FileReader(sf);
				BufferedReader br = new BufferedReader(fr);
				String s = br.readLine();
				while(s!= null) {
					stop.add(s);
					s = br.readLine();
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				return null;
			} catch (IOException e) {
				e.printStackTrace();
				return null;
			}
		} else {
			return null;
		}
		return stop;
	}
	
	public static List<Map> getKey(String fileID) {
		String sql = "select * from finalkey where fileid = " + fileID + 
					" and iskey = '1' order by cvalue desc ";
		System.out.println(sql);
		List<Map> key = new ArrayList<Map>();
		key = OperateDB.executeQuery(sql);
		if (key.size() < 1) {
			return null;
		} else {
			return key;
		}
		
	}
	
	public static List<Map> getLoadFile(String fileID) {
		String sql = "select * from loadfile where fileid = " + fileID;
		System.out.println(sql);
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		if (list.size() < 1) {
			return null;
		} else {
			return list;
		}
		
	}
}
